import paramiko
class FileSender:
    def __init__(self, IP, uname, passwd):
        self.ssh = paramiko.SSHClient()
        self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # ssh.connect(hostname='192.168.215.49', username='WRW', password='qwer')
        self.ssh.connect(hostname=IP, username= uname, password=passwd)

    def file_send(self, source_file ,target_folder):
        # 使用SFTP传输文件
        sftp = self.ssh.open_sftp()
        sftp.put(source_file, target_folder)  # 目标文件名可以按需更改
        sftp.close()
        # 关闭SSH连接
        # self.ssh.close()

if __name__ == '__main__':
    file_sender = FileSender("192.168.215.49", "WRW", "qwer")
    file_sender.file_send("alg.py","E:\\tttalg.py")
